home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
src
/
fig05_11.jar
/
Ch05
/
Fig05_11
/
Fig05_11.cpp
next >
Wrap
C/C++ Source or Header
|
1997-10-14
|
649b
|
27 lines
// Fig. 5.11: fig05_11.cpp
// Printing a string one character at a time using
// a non-constant pointer to constant data
#include <iostream.h>
void printCharacters( const char * );
int main()
{
char string[] = "print characters of a string";
cout << "The string is:\n";
printCharacters( string );
cout << endl;
return 0;
}
// In printCharacters, sPtr is a pointer to a character
// constant. Characters cannot be modified through sPtr
// (i.e., sPtr is a "read-only" pointer).
void printCharacters( const char *sPtr )
{
for ( ; *sPtr != '\0'; sPtr++ ) // no initialization
cout << *sPtr;
}